<?php

namespace App\Console\Commands;

use App\Console\Base;
use App\Models\Hall;
use common\enum\CommonEnum;
use Illuminate\Support\Facades\DB;

class SumUserAgent extends Base
{
    /**
     * 控制台命令 signature 的名称。
     *
     * @var string
     */
    protected $signature = self::PREFIX . 'sumuseragent {--hall_id=}';

    /**
     * 控制台命令说明。
     *
     * @var string
     */
    protected $description = 'SumUserAgent';

    /**
     * 执行控制台命令。
     *
     * @return mixed
     */
    public function handle()
    {
        $hallID   = $this->option('hall_id');
        $agentSum = DB::table('agent')->where(['hall_id' => $hallID, 'status' => CommonEnum::ENABLED, 'type' => CommonEnum::ENABLED])->count();
        $userSum  = DB::table('user')->where(['hall_id' => $hallID, 'status' => CommonEnum::ENABLED])->count();
        $updateData = [
            'agent_count' =>$agentSum,
            'user_count' =>$userSum,
        ];
        Hall::where(['id' => $hallID])->update($updateData);
    }
}
